#include "callbackdispatcher.h"
#include <stdlib.h>
#include <typeinfo>
#include <QtCore/QDebug>
#include <QtCore/QByteArray>
#include <string.h>
#include "widget.h"


void CallbackDispatcher::onMessage(void *parameters)
{
    if (parameters == NULL)
    {
        qDebug() << "NULL";
        return;
    }

    ICallbackParameters* parameter = reinterpret_cast<ICallbackParameters *>(parameters);

    char* c = (char*)parameters;

//    printf("%x %x\n", parameters, &parameters);
//    printf("%x %x\n", parameter, &parameter);
//    printf("%x %x\n", c, &c);
//    printf("%ld %x\n", c[0], &c[0]);
//    printf("%ld %x\n", c[1], &c[1]);
//    printf("%ld %x\n", c[2], &c[2]);
//    printf("%ld %x\n", c[3], &c[3]);
//    printf("%ld %x\n", c[4], &c[4]);
//    printf("%ld %x\n", c[5], &c[5]);
//    printf("%ld %x\n", c[6], &c[6]);
//    printf("%ld %x\n", c[7], &c[7]);
//    printf("%ld %x\n", c[8], &c[8]);
//    printf("%ld %x\n", c[9], &c[9]);
//    printf("%ld %x\n", c[10], &c[10]);
//    printf("%ld %x\n", c[11], &c[11]);

    int eventType = ((int*)(&c[4]))[0];

    for (int i=0; i<256; i++)
        printf("%x ", c[i] % 0xff);
    puts("\n---");
    printf("%d\n", eventType);
    fflush(stdout);

    //    if (PostMessage(WM_SIPEVENT, (WPARAM)parameters, 0))
    //    {
    //        PortSIP_delCallbackParameters(parameters);
    //    }


    switch(eventType)
    {
    case SIP_UNKNOWN:
        break;

    case SIP_REGISTER_SUCCESS:
        qDebug() << "SIP_REGISTER_SUCCESS";
        break;

    case SIP_REGISTER_FAILURE:
        qDebug() << "SIP_REGISTER_FAILURE";
        break;

    case SIP_INVITE_INCOMING:
    {
        qDebug() << "SIP_INVITE_INCOMING";
        int rt = PortSIP_answerCall(Widget::m_SIPLib, 1, false);
     }
        break;

    case SIP_INVITE_TRYING:
        qDebug() << "SIP_INVITE_TRYING";
        break;

    case SIP_INVITE_SESSION_PROGRESS:
        qDebug() << "SIP_INVITE_SESSION_PROGRESS";
        break;

    case SIP_INVITE_RINGING:
        qDebug() << "SIP_INVITE_RINGING";
        break;

    case SIP_INVITE_ANSWERED:
        break;

    case SIP_INVITE_FAILURE:
        break;

    case SIP_INVITE_UPDATED:
        break;

    case SIP_INVITE_CONNECTED:
        break;

    case SIP_INVITE_BEGINING_FORWARD:
        break;

    case SIP_INVITE_CLOSED:
        break;

    case SIP_REMOTE_HOLD:
        break;

    case SIP_REMOTE_UNHOLD:
        break;

    case SIP_RECEIVED_REFER:
        break;

    case SIP_REFER_ACCEPTED:
        break;

    case SIP_REFER_REJECTED:
        break;

    case SIP_TRANSFER_TRYING:
        break;

    case SIP_TRANSFER_RINGING:
        break;

    case SIP_ACTV_TRANSFER_SUCCESS:
        break;

    case SIP_ACTV_TRANSFER_FAILURE:
        break;

    case SIP_RECEIVED_SIGNALING:
        break;

    case SIP_SENDING_SIGNALING:
        break;

    case SIP_WAITING_VOICEMESSAGE:
        break;

    case SIP_WAITING_FAXMESSAGE:
        break;

    case SIP_RECV_DTMFTONE:
        break;

    case SIP_PRESENCE_RECV_SUBSCRIBE:
        break;

    case SIP_PRESENCE_ONLINE:
        break;

    case SIP_PRESENCE_OFFLINE:
        break;

    case SIP_RECV_OPTIONS:
        break;

    case SIP_RECV_INFO:
        break;

    case SIP_RECV_MESSAGE:
        break;

    case SIP_RECV_OUTOFDIALOG_MESSAGE:
        break;

    case SIP_SEND_MESSAGE_SUCCESS:
        break;

    case SIP_SEND_MESSAGE_FAILURE:
        break;

    case SIP_SEND_OUTOFDIALOG_MESSAGE_SUCCESS:
        break;

    case SIP_SEND_OUTOFDIALOG_MESSAGE_FAILURE:
        break;

    case SIP_PLAY_AUDIO_FILE_FINISHED:
        break;

    case SIP_PLAY_VIDEO_FILE_FINISHED:
        break;
    }
}
